import 'package:eplorex/pages/my/profile/profile_birthday_picker.dart';
import 'package:eplorex/utils/ColorUtil.dart';
import 'package:flutter/material.dart';

import '../../../utils/HttpUtil.dart';
import 'ButtonWidget.dart';

class EditBirthDayPage extends StatefulWidget {
  EditBirthDayPage({super.key, required this.birthDay,required this.changed});

  String birthDay;

  ValueChanged changed;

  @override
  State<EditBirthDayPage> createState() => _EditBirthDayPageState();
}

class _EditBirthDayPageState extends State<EditBirthDayPage> {

  void _submit(BuildContext context) {

    if(widget.birthDay!=null){
      HttpUtil.getInstance().post('/api/user/v1/my/profile/edit/birthday', data: widget.birthDay);
    }

  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          leading:  ButtonWidget(
            width: 80,
            height: 50,
            onPressed: () {
              Navigator.pop(context);
            },
            highlightedColor: ColorUtil.hexColor(0xf7f7f7),
            bgColor: ColorUtil.hexColor(0xffffff),
            bgHighlightedColor: ColorUtil.hexColor(0xf7f7f7),
            enabled: true,
            bgDisableColor: Colors.grey,
            borderRadius: 8.0,
            child: Text(
              "取消",
              textAlign: TextAlign.center,
              softWrap: true,
              style: TextStyle(
                fontSize: 16,
                fontWeight: FontWeight.w500,
                fontStyle: FontStyle.normal,
                color: ColorUtil.hexColor(0xA1A1A1),
                decoration: TextDecoration.none,
              ),
            ),
          ),
          title: Text("编辑名字"),actions: [
          ButtonWidget(
            width: 80,
            height: 50,
            onPressed: () {
              Navigator.pop(context);
              _submit(context);
            },
            highlightedColor: ColorUtil.hexColor(0xf7f7f7),
            bgColor: ColorUtil.hexColor(0xffffff),
            bgHighlightedColor: ColorUtil.hexColor(0xf7f7f7),
            enabled: true,
            bgDisableColor: Colors.grey,
            borderRadius: 8.0,
            child: Text(
              "确定",
              textAlign: TextAlign.center,
              softWrap: true,
              style: TextStyle(
                fontSize: 16,
                fontWeight: FontWeight.w400,
                fontStyle: FontStyle.normal,
                color: ColorUtil.hexColor(0x338FFF),
                decoration: TextDecoration.none,
              ),
            ),
          )
        ],),
      body: Container(
        height: 200,
        child: Column(children: [
          ListTile(
             onTap: (){
               bottomSheetDialog(context,ProfileBirthdayPicker(confirmPressed: (String date) {
                 setState(() {
                   widget.birthDay=date;
                   widget.changed.call(date);
                 });
               },));
             },
              leading: Text("生日信息",style: TextStyle(fontSize: 18),),
              trailing: Wrap(
                crossAxisAlignment: WrapCrossAlignment.center,
                children: [
                  Text(
                    widget.birthDay,
                    style: TextStyle(fontSize: 16, color: Colors.black45),
                  ),
                  Image(
                    color: Colors.black45,
                    image: AssetImage("images/arrow_right_icon.png"),
                    width: 20,
                  )
                ],
              ),
              splashColor: Colors.black)
        ],),
      ),
    );
  }

  //显示底部弹窗
  static void bottomSheetDialog(
      BuildContext context,
      Widget widget, {
        bool? isScrollControlled,
        bool? enableDrag,
        Color? backgroundColor,
      }) {
    showModalBottomSheet(
      context: context,
      isScrollControlled: isScrollControlled ?? true,
      enableDrag: enableDrag ?? true,
      backgroundColor: backgroundColor ?? Colors.white,
      builder: (ctx) {
        return widget;
      },
    );
  }

}
